﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NetFrameworkExtensions.Enterprise;
using NetFrameworkExtensions.BusinessLayer.Properties;

namespace NetFrameworkExtensions.BusinessLayer
{
  public class ObjectSourceImpl : IObjectSource
  {
    public IObjectRepository GetRepository(Type repositoryType)
    {
      if (repositoryType == null)
        throw new ArgumentNullException("repositoryType");
      if (!typeof(IObjectRepository).IsAssignableFrom(repositoryType))
        throw new ArgumentException(FormattedResources.RepositoryTypeDoNotImplementIObjectRepository(repositoryType.FullName));

      return (IObjectRepository)ServiceManager.Current.GetInstance(repositoryType);
    }

    public TRepository GetRepository<TRepository>() where TRepository : IObjectRepository
    {
      return (TRepository)GetRepository(typeof(TRepository));
    }
  }
}
